package org.example.SlApi.JbxxApi;

import io.restassured.RestAssured;
import io.restassured.response.Response;
import org.example.JycInfo;
import org.example.utils.ConPlsqla;
import org.example.utils.ReadConf;
import org.example.utils.TestDataLoader;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;


import static org.example.CookieHandlingFilter.cookies;
import static org.example.RestClient.givenWithCookies;
import static org.example.RestClient.loginAndUpdateCookies;
import static org.example.SlApi.JbxxApi.QyjbxxbcApi.initJyclist;

public class DqqyApi {//读取保存的企业基本信息





    public static void main(String[] args) throws IOException {
        DqqyApi();
    }

    public static int DqqyApi() throws IOException {
        // 登录并更新cookies

        loginAndUpdateCookies();

        RestAssured.baseURI = ReadConf.getHost(); // 设置基础URI
        List<JycInfo> jycInfoList = initJyclist(); // 调用方法来获取列表
        if (!jycInfoList.isEmpty()) {
            JycInfo firstJycInfo = jycInfoList.get(0); // 获取列表中的第一个元素
            String pripid = firstJycInfo.getPripid(); // 使用实际的getter方法
            String sbid = firstJycInfo.getSbid();
            String qylxdl = firstJycInfo.getQylxdl();

        Response response = givenWithCookies()

                .log().all()
//               .cookies(cookies)

                .get("/ywtSldj.do?method=edit&pripid="+pripid+"&sbid="+sbid+"&qylxdl="+qylxdl+"&select_mkid=1&csrftoken="); // 注意：可能需要有效的 CSRF Token
        System.out.println(cookies);
        int statusCode = Integer.parseInt(String.valueOf(response.getStatusCode()));
        System.out.println(statusCode);
        String body = response.asString();
//        System.out.println(body);


        return statusCode;
    }

        return 0;
    }

}
